//index.js
//获取应用实例
const app = getApp();
Page({
    data: {
        page: 1,
        pageSize: 10,
        list: []
    },
    onLoad: function () {
        this.getList();
    },
    onHide: function () {
    },

    select(e){
        app.globalData['selectedCoupon'] = e.currentTarget.dataset.item;
        app.navigateBack();
    },
    
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {
        this.data.page = 1;
        this.getList();
    },

    getList: function() {
        var _this = this;
        var object = {
            url: app.api.url.user.couponList,
            data: {page: _this.data.page, pageSize: _this.data.pageSize},
            success: function(res){
                if(res.status == 1) {
                    for(var i=0; i < res.data.length; i++) {
                        res.data[i].money = parseInt(res.data[i].money);
                    }

                    //test
                    
                    _this.setData({
                        list: [...res.data, ...res.data]
                    });
                } else {
                    app.showToast(res.info);
                }
            },
            complete: function() {
                wx.stopPullDownRefresh() //停止下拉刷新
            }
        }
        app.request(object);
    }
});
